from django.db import models

# Create your models here.

class Product(models.Model):
    id = models.AutoField(primary_key=True)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(Subcategory)
    name = models.CharField(max_length=300, blank=True) #商品名称
    brand = models.CharField(max_length=100, blank=True) #品牌
    size = models.CharField(max_length=50,blank=True) #型号
    count = models.CharField(max_length=50,blank=True) #数量
    min_price = models.DecimalField(max_digits=7, decimal_places=2) #最低价
    high_price = models.DecimalField(max_digits=7, decimal_places=2) #最高价
    img_url = models.CharField(max_length=500,blank=True) #显示图片
    description = models.CharField(max_length=200, blank=True) #描述
    seo_description = models.CharField(max_length=200, blank=True) #seo描述
    seo_keyword = models.CharField(max_length=50, blank=True) #seo关键字
    shop_count = models.IntegerField(default=0) #卖家数
    single_provide = models.BooleanField(default=False) #是否特供
    product_url = models.CharField(max_length=500,blank=True) #商品购买地址
    view_count = models.IntegerField(default=0)
    status = models.IntegerField(default=1)

    def __unicode__(self):
        return self.name

    class Meta:
        db_table = u'product'

class ProductShop(models.Model):
    id = models.AutoField(primary_key=True)
    product = models.ForeignKey(Product)
    shop = models.ForeignKey(Shop)
    model= models.CharField(max_length=100, blank=True)#型号,每个卖家商品标识，后期根据此数据自动更新价格及其它信息
    price = models.DecimalField(max_digits=7, decimal_places=2) #价格
    star = models.CharField(max_length=100, blank=True) #评价
    description = models.CharField(max_length=200, blank=True)
    product_url = models.CharField(max_length=500,blank=True) #商品购买地址
    status = models.IntegerField(default=1)

    class Meta:
        db_table = u'product_shop'

class ProductImage(models.Model):
    id = models.AutoField(primary_key=True)
    product = models.ForeignKey(Product)
    url = models.CharField(max_length=500,blank=True)

    class Meta:
        db_table = u'product_image'

class Shop(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=20, blank=True)
    img = models.ImageField(upload_to='shop/%Y/%m/%d')
    description = models.CharField(max_length=200, blank=True)

    def _unicode_(self):
        return self.name

    class Meta:
        db_table = u'shop'


class Category(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100, blank=True)

    def _unicode_(self):
        return self.name

    class Meta:
        db_table = u'category'

class Subcategory(models.Model):
    id = models.AutoField(primary_key=True)
    category = models.ForeignKey(Category)
    name = models.CharField(max_length=100,blank=True)
    product_count = models.IntegerField(default=0)

    def _unicode_(self):
        return self.name

    class Meta:
        db_table = u'subcategory'

class Email(models.Model):
    id = models.AutoField(primary_key=True)
    email = models.EmailField(max_length=100)
    status = models.CharField(max_length=1)
    description = models.CharField(max_length=100)
    date = models.DateTimeField(auto_now_add=True)
    def _unicode_(self):
        return self.email

    class Meta:
        db_table = u'email'

class Search(models.Model):
    id = models.AutoField(primary_key=True)
    q = models.CharField(max_length=100,blank=True)
    date = models.DateTimeField(auto_now_add=True)

    def _unicode_(self):
        return self.q

    class Meta:
        db_table = u'search'

class FocusProduct():
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100,blank=True)
    date = models.DateTimeField(auto_now_add=True)

    def _unicode_(self):
        return self.name

    class Meta:
        db_table = u'email'

